home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / PRGMMING / CPP100.ZIP / CPPLGEN1.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-22  |  11.4 KB  |  344 lines

  1. /*****************************************************************************/
  2. /*       (C) 1993,1994 R. NADE - M. GRANDCHAMP - All Rights Reserved         */
  3. /*****************************************************************************/
  4. /*    This source-code is NOT public domain nor Freeware, this is part of    */
  5. /*              'The C Programming Package' which is Shareware.              */
  6. /*   If you use this code, please register and get a free Full-VGA version   */
  7. /*****************************************************************************/
  8.                             /*-------------------*
  9.                              *     CPPLGEN1.C    *
  10.                              *   Mouse programs  *
  11.                              *    & utilities    *
  12.                              *-------------------*/
  13.  
  14.  /* Included Files */
  15.  # include <stdio.h>
  16.  # include <io.h>
  17.  # include <dos.h>
  18.  # include <fcntl.h>
  19.  # include <bios.h>
  20.  # include <stdlib.h>
  21.  # include <conio.h>
  22.  # include <alloc.h>
  23.  # include <process.h>
  24.  # include <time.h>
  25.  # include <alloc.h>
  26.  # include <string.h>
  27.  
  28.  /* Global Variables */
  29.  extern int bm,i,j,k,l,m,n,t,x,xm,y,ym,z,soundvar,button,x1,x2,y1,y2,xms,yms;
  30.  extern int divx,divy,xmsa,ymsa;
  31.  extern unsigned int jouract,monthact,yearact;
  32.  extern unsigned char nc1[],nc2[],trashret[];
  33.  extern unsigned char screen[],screen2[],screenhelp[];
  34.  extern struct text_info ti;
  35.  extern struct text_info thelp;
  36.  
  37.  /*---------*
  38.   * SOUND 1 *
  39.   *---------*/
  40.   void sound1()
  41.     {
  42.       if(soundvar==1){
  43.         sound(500);                    delay(200);
  44.         nosound();
  45.       }
  46.     }
  47.  /*---------*
  48.   * SOUND 2 *
  49.   *---------*/
  50.   void sound2()
  51.     {
  52.       if(soundvar==1){
  53.         sound(300);                    delay(100);
  54.         sound(500);                    delay(200);
  55.         sound(700);                    delay(100);
  56.         nosound();
  57.       }
  58.     }
  59.  /*---------------*
  60.   *     SOUND 3   *
  61.   * right answer  *
  62.   *---------------*/
  63.   void sound3()
  64.     {
  65.       if(soundvar==1){
  66.         sound(300);                    delay(100);
  67.         sound(500);                    delay(200);
  68.         sound(300);                    delay(100);
  69.         sound(700);                    delay(100);
  70.         sound(1000);                   delay(300);
  71.         nosound();
  72.       }
  73.     }
  74.  /*---------------*
  75.   *      SOUND 4  *
  76.   * wrong answer  *
  77.   *---------------*/
  78.   void sound4()
  79.     {
  80.       if(soundvar==1){
  81.         sound(300);                    delay(100);
  82.         sound(500);                    delay(100);
  83.         sound(300);                    delay(200);
  84.         sound(200);                    delay(200);
  85.         sound(150);                    delay(200);
  86.         nosound();
  87.       }
  88.     }
  89.  /*-----------------*
  90.   * CHECK THE MOUSE *
  91.   *-----------------*/
  92.   int check_the_mouse()
  93.     {
  94.       union REGS inregs,outregs;
  95.       inregs.x.ax=0x00;
  96.       int86(0x33,&inregs,&outregs);
  97.       k=outregs.x.ax;
  98.       if(k==0)                         return(0);
  99.       else                             return(1);
  100.     }
  101.  /*---------------*
  102.   * PUT THE MOUSE *
  103.   *---------------*/
  104.   void put_the_mouse(enx,eny)
  105.     int enx,eny;
  106.     {
  107.       union REGS inregs,outregs;
  108.       /* co-ordinates are in pixels, we convert them in lines */
  109.       /* and columns using the factors depending upon the     */
  110.       /* videocard                                            */
  111.       inregs.x.ax=0x04;                inregs.x.cx=(enx-1)*divx;
  112.       inregs.x.dx=(eny-1)*divy;        int86(0x33,&inregs,&outregs);
  113.     }
  114.  /*-----------------*
  115.   * LIMIT THE MOUSE *
  116.   *-----------------*/
  117.   void limit_the_mouse()
  118.     {
  119.       union REGS inregs,outregs;
  120.       /* co-ordinates are in pixels, we convert them in lines */
  121.       /* and columns using the factors depending upon the     */
  122.       /* videocard                                            */
  123.       /* Horizontal limits between 0 and 80 columns           */
  124.       inregs.x.ax=0x07;                inregs.x.cx=((x1-1)*divx);
  125.       inregs.x.dx=((x2-1)*divx);       int86(0x33,&inregs,&outregs);
  126.       /* Vertical limits between 0 and 25, 43, 50 lines */
  127.       inregs.x.ax=0x08;                inregs.x.cx=((y1-1)*divy);
  128.       inregs.x.dx=((y2-1)*divy);       int86(0x33,&inregs,&outregs);
  129.       /* The put the mouse in the upper-left corner */
  130.       /* of this new window                         */
  131.       put_the_mouse((x1+1),(y1+1));
  132.     }
  133.  /*----------------*
  134.   * SHOW THE MOUSE *
  135.   *----------------*/
  136.   void show_the_mouse()
  137.     {
  138.       union REGS inregs,outregs;
  139.       inregs.x.ax=0x01;                int86(0x33,&inregs,&outregs);
  140.     }
  141.  /*----------------*
  142.   * HIDE THE MOUSE *
  143.   *----------------*/
  144.   void hide_the_mouse()
  145.     {
  146.       union REGS inregs,outregs;
  147.       inregs.x.ax=0x02;                int86(0x33,&inregs,&outregs);
  148.     }
  149.  /*-----------------*
  150.   * GET MOUSE STATE *
  151.   *-----------------*/
  152.   void get_mouse_state()
  153.     {
  154.       union REGS inregs,outregs;
  155.       inregs.x.ax=0x03;                int86(0x33,&inregs,&outregs);
  156.       button=outregs.x.bx;
  157.       x=outregs.x.cx;                  y=outregs.x.dx;
  158.       xm=(x/divx)+1;                   ym=(y/divy)+1;
  159.       if(button>0){
  160.         /* at least, one button has been pressed */
  161.     bm=1;                          delay(200);
  162.       }
  163.       else                             bm=0;
  164.     }
  165.  /*-----------------*
  166.   * GET SYSTEM DATE *
  167.   *-----------------*/
  168.   void get_the_system_date()
  169.     {
  170.       struct date d;
  171.       /* Results are integers */
  172.       getdate(&d);                     yearact=d.da_year;
  173.       monthact=d.da_mon;                jouract=d.da_day;
  174.     }
  175.  /*-----------------------*
  176.   * LEFT JUSTIFY THE TEXT *
  177.   *-----------------------*/
  178.   void left_justify_the_text(thetext,nbcars)
  179.     unsigned char thetext[81];
  180.     int nbcars;
  181.     {
  182.       i=strlen(thetext);
  183.       /* Fill the beginning of trashret[] with the chars */
  184.       for(j=0; j<i; j++)               trashret[j]=thetext[j];
  185.       /* And the rest with spaces */
  186.       for(j=i; j<nbcars; j++)          trashret[j]=0x20;
  187.       trashret[nbcars]=0x00;
  188.     }
  189.  /*------------------------*
  190.   * RIGHT JUSTIFY THE TEXT *
  191.   *------------------------*/
  192.   void right_justify_the_text(thetext,nbcars)
  193.     unsigned char thetext[81];
  194.     int nbcars;
  195.     {
  196.       i=strlen(thetext);               k=nbcars-i;
  197.       /* Fill the beginning of trashret[] with spaces */
  198.       for(j=0; j<k; j++)               trashret[j]=0x20;
  199.       /* And the rest with the chars */
  200.       for(j=0; j<i; j++)               trashret[k+j]=thetext[j];
  201.       trashret[nbcars]=0x00;
  202.     }
  203.  /*-----------------------------------------*
  204.   * RIGHT JUSTIFY (numeric variable,nbcars) *
  205.   *     with less than 5 chars in nc2[]     *
  206.   *-----------------------------------------*/
  207.   void right_justify(variable,nbcars)
  208.     int variable,nbcars;
  209.     {
  210.       itoa(variable,nc1,10);
  211.       if(variable<10){
  212.     nc1[3]=nc1[0];                 nc1[0]=0x20;
  213.     nc1[1]=0x20;                   nc1[2]=0x20;
  214.     nc1[4]=0x00;
  215.       }
  216.       if((variable>9)&&(variable<100)){
  217.     nc1[3]=nc1[1];                 nc1[2]=nc1[0];
  218.     nc1[0]=0x20;                   nc1[1]=0x20;
  219.     nc1[4]=0x00;
  220.       }
  221.       if((variable>99)&&(variable<1000)){
  222.     nc1[3]=nc1[2];                 nc1[2]=nc1[1];
  223.     nc1[1]=nc1[0];                 nc1[0]=0x20;
  224.     nc1[4]=0x00;
  225.       }
  226.       if(variable==0){
  227.     nc1[0]=0x20;                   nc1[1]=0x20;
  228.     nc1[2]=0x20;                   nc1[3]=0x30;
  229.     nc1[4]=0x00;
  230.       }
  231.       /* If the number if greater than 999, it is OK with 4 digits */
  232.       /* Put it at the right size if less than 4 digits            */
  233.       if(nbcars==1){
  234.     nc2[0]=nc1[3];                 nc2[1]=0x00;
  235.       }
  236.       if(nbcars==2){
  237.     nc2[0]=nc1[2];                 nc2[1]=nc1[3];
  238.     nc2[2]=0x00;
  239.       }
  240.       if(nbcars==3){
  241.     nc2[0]=nc1[1];                 nc2[1]=nc1[2];
  242.     nc2[2]=nc1[3];                 nc2[3]=0x00;
  243.       }
  244.       if(nbcars==4)                    strcpy(nc2,nc1);
  245.     }
  246.  /*-------------*
  247.   * SAVE SCREEN *
  248.   *-------------*/
  249.   void save_screen()
  250.     {
  251.       /* Save the whole screen */
  252.       hide_the_mouse();               gettext(1,1,80,25,screen);
  253.       /* Save the current window info., the cursor position */
  254.       /* and the mouse position */
  255.       gettextinfo(&ti);                show_the_mouse();
  256.       xms=xm;                          yms=ym;
  257.     }
  258.  /*----------------*
  259.   * RESTORE SCREEN *
  260.   *----------------*/
  261.   void restore_screen()
  262.     {
  263.       hide_the_mouse();
  264.       /* Restore the saved screen */
  265.       nc1[1]=0x00;                     puttext(1,1,80,25,screen);
  266.       /* Use the values saved for the window, the cursor and */
  267.       /* the mouse as before the save                        */
  268.       nc1[0]=ti.winleft;               x1=atoi(nc1);
  269.       nc1[0]=ti.winright;              x2=atoi(nc1);
  270.       nc1[0]=ti.wintop;                y1=atoi(nc1);
  271.       nc1[0]=ti.winbottom;             y2=atoi(nc1);
  272.       xm=xms;                          ym=yms;
  273.       /* Put the window to its initial value */
  274.       window(x1,y1,x2,y2);
  275.       /* Put the cursor at the same place */
  276.       nc1[0]=ti.curx;               x=atoi(nc1);
  277.       nc1[0]=ti.cury;               y=atoi(nc1);
  278.       gotoxy(x,y);
  279.       /* And the colours attributes */
  280.       nc1[0]=ti.attribute;           z=atoi(nc1);
  281.       textattr(z);                     show_the_mouse();
  282.     }
  283.  /*------------------*
  284.   * SAVE HELP SCREEN *
  285.   *------------------*/
  286.   void save_help_screen()
  287.     {
  288.       /* Save the full displayed screen */
  289.       hide_the_mouse();               gettext(40,1,80,25,screenhelp);
  290.       /* Save the current info. on the window     */
  291.       /* The position of the cursor and the mouse */
  292.       gettextinfo(&thelp);             show_the_mouse();
  293.       xmsa=xm;                         ymsa=ym;
  294.     }
  295.  /*---------------------*
  296.   * RESTORE HELP SCREEN *
  297.   *---------------------*/
  298.   void restore_help_screen()
  299.     {
  300.       /* display the saved window */
  301.       nc1[1]=0x00;                     puttext(40,1,80,25,screenhelp);
  302.       /* Use the values saved for the window, the cursor and */
  303.       /* the mouse as before the save                        */
  304.       nc1[0]=thelp.winleft;            x1=atoi(nc1);
  305.       nc1[0]=thelp.winright;           x2=atoi(nc1);
  306.       nc1[0]=thelp.wintop;             y1=atoi(nc1);
  307.       nc1[0]=thelp.winbottom;          y2=atoi(nc1);
  308.       xm=xmsa;                         ym=ymsa;
  309.       /* Put the window to its initial value */
  310.       window(x1,y1,x2,y2);
  311.       /* Put the cursor at the same place */
  312.       nc1[0]=thelp.curx;               x=atoi(nc1);
  313.       nc1[0]=thelp.cury;               y=atoi(nc1);
  314.       gotoxy(x,y);
  315.       /* And the colours attributes */
  316.       nc1[0]=thelp.attribute;          z=atoi(nc1);
  317.       textattr(z);
  318.     }
  319.  /*--------------------*
  320.   * SAVE SCREEN 2 *
  321.   *--------------------*/
  322.   void save_screen2(enx,eny)
  323.     int enx,eny;
  324.     {
  325.       /* Save the zone defined by the upper-left corner co-ordinates */
  326.       /* given as parameters with 25 chars wide and 11 lines high */
  327.       hide_the_mouse();
  328.       gettext(enx,eny,(enx+25),(eny+11),screen2);
  329.       show_the_mouse();
  330.     }
  331.  /*------------------*
  332.   * RESTORE SCREEN 2 *
  333.   *------------------*/
  334.   void restore_screen2(enx,eny)
  335.     int enx,eny;
  336.     {
  337.     /* Display the saved screen */
  338.       hide_the_mouse();
  339.       puttext(enx,eny,(enx+25),(eny+11),screen2);
  340.       show_the_mouse();
  341.     }
  342.  /* End of the Module *//*--------------------*/
  343.  
  344.